Title: SQL W3S (By-BKK) / 038 Insert Into Select
Tags: Obsidian_to_Anki

Q: What does the SQL INSERT INTO SELECT statement do?
A: It copies data from one table and inserts it into another table

Q: True or False: The INSERT INTO SELECT statement affects existing records in the target table
A: False. Existing records in the target table are unaffected

Q: What is required between source and target tables when using INSERT INTO SELECT?
A: The data types must match

Q: Show the syntax to copy all columns from one table to another using INSERT INTO SELECT
A: INSERT INTO table2 SELECT * FROM table1 WHERE condition;

Q: Show the syntax to copy only selected columns with INSERT INTO SELECT
A: INSERT INTO table2 (column1, column2) SELECT column1, column2 FROM table1 WHERE condition;

Q: Provide an example of copying SupplierName, City, Country from Suppliers to Customers
A: INSERT INTO Customers (CustomerName, City, Country) SELECT SupplierName, City, Country FROM Suppliers;

Q: Give an example of copying all columns from Suppliers to Customers
A: INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;

Q: How do you copy only German suppliers into the Customers table using INSERT INTO SELECT?
A: INSERT INTO Customers (CustomerName, City, Country) SELECT SupplierName, City, Country FROM Suppliers WHERE Country='Germany';

Q: True or False: Columns that are not filled with data when using INSERT INTO SELECT will contain NULL
A: True

Q: Reverse card:
What does the SQL INSERT INTO SELECT statement do?
A: It copies data from one table and inserts it into another table

Q: Reverse card:
What must be true about data types in source and target tables for INSERT INTO SELECT?
A: The data types must match

Q: Reverse card:
Will columns not filled with data when using INSERT INTO SELECT contain NULL?
A: True